Often, when code is being debugged, a problem manifested at one location of the code is rooted elsewhere (somewhere earlier in the code), where it was caused, making it difficult to identify and isolate the problem. By adding assertions to the code, assumptions may be examined and compared with the actual behavior of the code when executed.
Assertions may provide a useful tool that allows documenting an assumption within the code and having this assumption checked automatically at run-time or post-process.
Typically, an assertion includes a predicate, or Boolean condition, that the user—typically a debugging expert (hereinafter referred to as the “user”)—expects to be always true. If the condition returns false, then the assumption is found to be incorrect. An incorrect assumption may indicate that there is a bug in the code. A debugging tool may trigger, upon determining the existence of a false assertion, a halt of the execution, so as to allow the user to determine the cause of the problem.
Programmers may use assertions to help specify programs and to reason about program correctness.